<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	
	
    protected function _initAutoload() {
        $modelLoader = new Zend_Application_Module_Autoloader(array(
                        'namespace' => '',
                        'basePath' => APPLICATION_PATH.'/modules/default'));
                        
        if(Zend_Auth::getInstance()->hasIdentity()) {
		
			Zend_Registry::set('role', Zend_Auth::getInstance()->getStorage()->read()->role);
	
		} else {
			Zend_Registry::set('role', 'guest');
		}
		
		
		//print_r(Zend_Registry::get('role'));
		//exit;
        $this->_acl = new Model_LibraryAcl;
        $this->_auth = Zend_Auth::getInstance();
        
        $fc = Zend_Controller_Front::getInstance();
        $fc->registerPlugin(new Plugin_AccessCheck($this->_acl));
        
        
        return $modelLoader;
    }
    

	/**
	 * Gestion des sessions
	 */
	
	protected function _initSession() {
	//Le logger
		$logger = new Zend_Log();
		//Le writer
		$writer =new Zend_Log_Writer_Firebug();
		$logger->addWriter($writer);
			Zend_Registry::set ( 'logger', $logger );
				// On initialise la session
		$session = new Zend_Session_Namespace ( 'zftutoriel', true );
		Zend_Registry::set ( 'session', $session );
		Zend_Registry::set ( 'Zend_Locale', 'en' );	
		//Zend_Session::start();
			
		//return $session;
	}
	
	/**
	 * Gestion de l'internationalisation
	 *
	 * @return Zend_Translate
	 */
	protected function _initTranslate() {
		// On r�cup�re la session du site.
		$session = Zend_Registry::get ( 'session' );
		// On d�finit la langue par d�faut sur le site.
		$locale = new Zend_Locale ( 'fr' );
		// On enregistre cette langue dans notre registre.
		Zend_Registry::set ( 'Zend_Locale', $locale );
		// Si la langue existe en session, on r�cup�re la session, sinon on prend la valeur par d�faut.
		$langLocale = isset ( $session->lang ) ? $session->lang : $locale;
		// On lance l'objet de traduction en lui passant les fichiers de langues
		$translate = new Zend_Translate ( 'array', APPLICATION_PATH . '/languages/fr_FR.php', 'fr' );
		$translate->addTranslation ( APPLICATION_PATH . '/languages/en_US.php', 'en' );
		// On lui passe la langue courante du site
		$translate->setLocale ( $langLocale );
		// Important pour utiliser le helper.
		Zend_Registry::set ( 'Zend_Translate', $translate );
		
		
	}	
	
	/**
	 * Initialisation & Enregistrement des vues
	 */
	protected function _initMails() {
		$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', 'mail' );
		$mailConfig = $config->toArray ();
		Zend_Registry::set ('Mail_Config', $mailConfig ['mail'] ['config'] );
		Zend_Registry::set ('Mail_From', $mailConfig ['mail'] ['from'] );
	
	}    

	protected function _initViewHelpers() {
		$this->bootstrap('layout');
		$layout = $this->getResource('layout');
		$view = $layout->getView();
		
		$view->setHelperPath(APPLICATION_PATH.'/helpers', '');
		
		$view->doctype('HTML4_STRICT');
		$view->headMeta()->appendHttpEquiv('Content-type', 'text/html;charset=utf-8');
						
						
		
		$view->headTitle()->setSeparator(' - ')
			 ->headTitle('GMV');
	
		//Chargement CSS
		$view->headLink()->prependStylesheet(APPLICATION_URL.'/css/screen.css', 'screen');
		$view->headLink()->prependStylesheet(APPLICATION_URL.'/css/mbContainer.css', 'screen');
		$view->headLink()->prependStylesheet(APPLICATION_URL.'/css/scrollable.css', 'screen');
		$view->headLink()->prependStylesheet(APPLICATION_URL.'/css/scroll.css', 'screen');
		$view->headLink()->prependStylesheet(APPLICATION_URL.'/css/contextMenu.css', 'screen');
		
		//Chargement JS
		
		$view->headScript()->prependFile(APPLICATION_URL.'/js/gmap.js');
		$view->headScript()->prependFile(APPLICATION_URL.'/js/mbContainer.js');
		$view->headScript()->prependFile(APPLICATION_URL.'/js/jquery.timer.js');
		$view->headScript()->prependFile(APPLICATION_URL.'/js/jquery.metadata.js');
		$view->headScript()->prependFile(APPLICATION_URL.'/js/jquery.ui.js');
		$view->headScript()->prependFile(APPLICATION_URL.'/js/jquery.tools.min.js');
		$view->headScript()->prependFile('http://maps.google.com/maps/api/js?sensor=true');
		
		
				 
		// base helpers
  		$view->addHelperPath(APPLICATION_PATH . '/views/helpers');             
  		$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
  		$viewRenderer->setView($view);		
  		
	}
	
}

